#!/usr/bin/env python

import telnetlib
import threading
import queue

#测试功能
def get_ip_status(ip, port=80):
	server = telnetlib.Telnet()
	try:
		server.open(ip, port)
		print('{0} port {1} is open'.format(ip, port))
	except Exception as err:
		pass
#		print('{0} port {1} is not open'.format(ip, port))
	finally:
		server.close()

def check_open(q):
    try:
        while True:
            ip = q.get_nowait()
            get_ip_status(ip)
    except queue.Empty as e:
        print("no")

if __name__ == '__main__':
	q = queue.Queue()
	for i in range(20, 255):
		ip = "10.28.46.{0}".format(i)
		q.put(ip)
	threads = []
	for i in range(70):
		t = threading.Thread(target=check_open, args=(q,))
		t.start()
		threads.append(t)
	for t in threads:
		t.join()

